package com.cz.video.web.controller.website;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.cz.video.common.annotation.LegalValidate;
import com.cz.video.common.annotation.Log;
import com.cz.video.common.core.controller.BaseController;
import com.cz.video.common.core.domain.PageQuery;
import com.cz.video.common.core.domain.R;
import com.cz.video.common.core.domain.entity.SysUser;
import com.cz.video.common.core.page.TableDataInfo;
import com.cz.video.common.enums.BusinessType;
import com.cz.video.common.exception.ServiceException;
import com.cz.video.system.service.ISysUserService;
import com.cz.video.website.domain.WebsiteMsg;
import com.cz.video.website.domain.bo.WebsiteMsgBo;
import com.cz.video.website.domain.bo.WebsiteMsgBo;
import com.cz.video.website.service.IWebsiteMsgService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  信息表 前端控制器
 * </p>
 *
 * @author LLF
 * @since 2023-10-16
 */
@Tag(name = "信息表管理")//为Swagger文档生成的API添加了标签
@Validated//方法参数校验的注解
@RestController
@RequiredArgsConstructor//自动生成构造函数
@RequestMapping("/website-msg")
public class WebsiteMsgController extends BaseController {
    public final IWebsiteMsgService websiteMsgService;
    private final ISysUserService userService;

    //    @SaCheckPermission("website:Msg:add")
    /**
     * 添加信息表
     * @param websiteMsg
     * @return
     */
    @SaCheckPermission("website:Msg:add")//基于Sa-Token进行登录和权限校验
    @Operation(summary = "添加信息表")
    @Log(title = "添加信息表", businessType = BusinessType.INSERT)
    @PostMapping("")
    @LegalValidate//合法检验
    public R<Void> add(@RequestBody @Validated WebsiteMsg websiteMsg){
        return toAjax(websiteMsgService.insertMsg(websiteMsg));
    }

    /**
     * 删除信息表
     * @param id
     * @return
     */
    @SaCheckPermission("website:Msg:delete")
    @Operation(summary = "删除信息表")
    @Log(title = "删除信息表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable int id){
        int result = websiteMsgService.deleteById(id);
        if (result > 0) {
            return toAjax(result);
        } else {
            throw new ServiceException("删除信息表失败，该信息表不存在。");
        }
    }

    /**
     * 修改信息表
     */
    @Operation(summary = "修改信息表")
    @SaCheckPermission("website:Msg:edit")
    @Log(title = "信息表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody WebsiteMsgBo websiteMsg) {
        return toAjax(websiteMsgService.updateMsg(websiteMsg));//调用方法包装成R<void>返回
    }

    /**
     * 获取信息表
     */
    @SaCheckPermission("website:Msg:list")
    @GetMapping("/list")
    public TableDataInfo list(WebsiteMsgBo websiteMsg, PageQuery pageQuery) {
        return websiteMsgService.selectPageMsgList(websiteMsg, pageQuery);
    }




}
